var app = getApp()

Page({
  data: {
    cid: null,
    countSign: 0,
    over: null,
    attend: null,
    showLoading: true,
    details: null,
    display1: '',
    display2: 'none',
    displayTable: ''
  },
  onReady: function () {
    if (app.globalData.userNum == 2) {
      wx.setNavigationBarColor({
        frontColor: '#000000',
        backgroundColor: '#99CCCC',
        animation: {
          duration: 550
        }
      })
    }
  },
  onLoad: function (options) {
    console.log(options)
    this.setData({ cid: options.cid })
    this.setData({ countSign: parseInt(options.countSign) })
  },
  onShow: function () {
    var that = this
    var CId = that.data.cid
    var url = app.globalData.basePath + "find/getClass.do";
    wx.request({
      url: url,
      method: 'POST',
      header: {
        'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8',
      },
      data: {
        'CId': CId
      },
      success: function (result) {
        console.log(result)
        var overDate = result.data.overtime;
        overDate = overDate.substr(0, overDate.length - 2);
        overDate = overDate.replace(/-/g, '/');
        var over = Date.parse(new Date(overDate));
        that.setData({ over: over })
        var attendDate = result.data.attendtime;
        attendDate = attendDate.substr(0, attendDate.length - 2);
        attendDate = attendDate.replace(/-/g, '/');
        var attend = Date.parse(new Date(attendDate));
        that.setData({ attend: attend })
        console.log(overDate)
        console.log(over)
        console.log(attend)
        if( over >= attend){
          that.setData({ showLoading: false })
          that.showTotal()
        }else{
          that.setData({ display1: 'none' })
          that.setData({ display2: '' })
        }
      }
    })
  },

  showTotal: function(){
    var that = this
    var CId = that.data.cid
    var countSign = that.data.countSign
    var normal = 0
    var leave = 0
    var early = 0
    var late = 0
    var absence = 0
    var url = app.globalData.basePath + "StuFind/findStudentsDetail.do";

    wx.request({
      url: url,
      method: 'POST',
      header: {
        'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8',
      },
      data: {
        'CId': CId
      },
      success: function (result) {
        console.log(result.data)
        if (JSON.stringify(result.data) === '[]') {
          that.setData({ displayTable: 'none' })
          wx.showModal({
            title: '提示',
            showCancel: false,
            content: '还没有学生加入该课程',
            success: function (res) {
              console.log("mmp")  
            }
          })
        }else{
          that.setData({ details: result.data })
        }
      }
    })
  },
  recent:function(){
    var that = this
    var cid = that.data.cid
    var countSign = that.data.countSign
    var url = "../recent/recent?cid=" + cid + "&countSign=" + countSign
    wx.navigateTo({
      url: url,
    })
  }

})